import router from "@/router";
import { Toast } from "vant";
import {
  petindex,
  buypet,
  top,
  petdetail,
  profitlogs,
  versions,
  petActIndex,
  petActDetail,
} from "@/server/market";
import { setStorage, setSession, removeStorage } from "@/utils/common";
export default {
  state: () => ({
    top: "",
    profitlogsdata: "",
    versions: "",
  }),
  mutations: {
    settop(state, data) {
      state.top = data;
    },
    setprofitlogsdata(state, data) {
      state.profitlogsdata = data;
    },
    setversions(state, data) {
      state.versions = data;
    },
  },
  actions: {
    petindex({ commit }, data) {
      return new Promise((resolve, reject) => {
        petindex().then((res) => {
          if (res.code == 0) {
            resolve(res.data);
          }
        });
      });
    },
    buypet({ commit }, data) {
      return new Promise((resolve, reject) => {
        buypet(data).then((res) => {
          resolve(res);
        });
      });
    },
    top({ commit }, data) {
      return new Promise((resolve, reject) => {
        top(data).then((res) => {
          commit("settop", res.data);
          resolve(res.data);
        });
      });
    },
    petdetail({ commit }, data) {
      return new Promise((resolve, reject) => {
        petdetail(data).then((res) => {
          if (res.code == 0) {
            resolve(res.data);
          }
        });
      });
    },
    profitlogs({ commit }, data) {
      return new Promise((resolve, reject) => {
        profitlogs(data).then((res) => {
          if (res.code == 0) {
            commit("setprofitlogsdata", res.data);
            resolve(res.data);
          }
        });
      });
    },
    getVersions({ commit }, data) {
      return new Promise((resolve, reject) => {
        versions(data).then((res) => {
          if (res.code == 0) {
            commit("setversions", res);
            resolve(res);
          } else {
            Toast(res.msg);
          }
        });
      });
    },
    petActIndex({ commit }, data) {
      return new Promise((resolve, reject) => {
        petActIndex(data).then((res) => {
          if (res.code == 0) {
            resolve(res.data);
          } else {
            Toast(res.msg);
          }
        });
      });
    },
    petActDetail({ commit }, data) {
        return new Promise((resolve, reject) => {
            petActDetail(data).then((res) => {
            if (res.code == 0) {
              resolve(res);
            } else {
              Toast(res.msg);
            }
          });
        });
      },
  },

  getters: {},
};
